//
//  LWZZAFN.m
//  LWZZOnTheWay
//
//  Created by 罗钧友 on 16/1/27.
//  Copyright © 2016年 罗钧友. All rights reserved.
//

#import "LWZZAFN.h"
#import "Reachability.h"
#import <AFNetworking.h>

@implementation LWZZAFN
+(instancetype)shareAFN{
    static LWZZAFN *appTools=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        appTools = [[LWZZAFN alloc]init];
    });
    return appTools;
}

-(void)getDataWithUrl:(NSString *)urlStr success:(BLOCK)block error:(ERROR)errorBlock{
    
    //    网络判断
    Reachability *reach=[Reachability reachabilityWithHostName:@"www.apple.com"];
    switch ([reach currentReachabilityStatus]) {
            
        case NotReachable:{
            // 没有网络连接
            
        }
            break;
            
        case ReachableViaWWAN:{
            // 使用3G网络
        }
            
            break;
            
        case ReachableViaWiFi:{
            //wifi
            AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
            manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
            [manager GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                block(responseObject);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                errorBlock(error);
            }];
        }
            break;
    }
    
    
    
}


@end
